clear mata
clear matrix
clear
set more off
set maxvar 10000
global data "C:\Users\taiwo\Downloads\Nigeria Data\New_Analysis061424"
cd "$data"
*2003 has spelling names and codes different from the other years*
use "$data\NGMR4AFL.DTA", clear
*to make the sampling stratification alike*
tab mv024
decode mv024, gen (mv024_1)
replace mv024_1="nc" if mv024==1
replace mv024_1="ne" if mv024==2
replace mv024_1="nw" if mv024==3
replace mv024_1="se" if mv024==4
replace mv024_1="ss" if mv024==5
replace mv024_1="sw" if mv024==6
tab mv025
decode mv025, gen (mv025_1)
tab smstate
decode smstate, gen (smstate_1)
replace smstate_1="zamfara" if smstate_1=="zamfora" 
replace smstate_1="fct abuja" if smstate_1=="abuja (fct)" 
replace smstate_1=lower(smstate_1)
gen mv022_1 = mv024_1 +" "+ smstate_1+" "+  mv025_1
encode mv022_1, gen (mv022_2)
bro mv022_2
save "$data\NGMR4AFL_2003 ammended.dta", replace
use "$data\NGMR7AFL.DTA", clear
append using "$data\NGMR6AFL.DTA"
append using "$data\NGMR52FL.DTA"
*to make the sampling stratification alike*
decode mv024, gen (mv024_1)
replace mv024_1="nc" if mv024==1
replace mv024_1="ne" if mv024==2
replace mv024_1="nw" if mv024==3
replace mv024_1="se" if mv024==4
replace mv024_1="ss" if mv024==5
replace mv024_1="sw" if mv024==6
decode mv025, gen (mv025_1)
decode smstate, gen (smstate_1)
replace smstate_1=lower(smstate_1)
gen mv022_1 = mv024_1 +" "+ smstate_1+" "+  mv025_1
encode mv022_1, gen (mv022_2)
bro mv022_2
append using "$data\NGMR4AFL_2003 ammended.dta"
tab mv022_2 mv007
*recode of household head sex/gender, HH head male(1) female(0)*
*make unique strata values by region/urban-rural (label option automatically labels the results) 
egen strata = group(mv024 mv025), label 
*check results 
tab strata mv007, missing

*Recode missing values to '.'
summ mv152
mvdecode mv152, mv(98,99)

summ  mv105 mv106 mv134 mv135 mv149 mv732 mv741
*7 not dejure resident, 8 is DK (don't know), and 9 is missing-treat as missing*
mvdecode mv105 mv106  mv134 mv135 mv149 mv732 mv741, mv(7,8,9)

summ mv104 mv107 mv130 mv131 mv133 mv150 mv152 mv717 
*98 is DK (don't know or unknown) and 99 is missing-treat as missing*
mvdecode mv104 mv107 mv130 mv131 mv133 mv150 mv152 mv717 , mv(98,99,97)

summ  mv131  
*998 is DK (don't know or unknown) and 999 is missing-treat as missing*
mvdecode  mv131, mv(999,998,997)


*recode of household head sex/gender, HH head male(1) female(0)*
tab mv151, missing
recode mv151 (2=0), gen(hheadsex)
label var hheadsex "1=male and 0=female"
gen hheadage=mv152
label var hheadage "Household head's age (years)"
gen age=mv012
gen sex=1
recode mv102 (2=0), gen (urban)
recode mv104 (95=1) (0/90=0) (96/97=0), gen (always_residents)
recode mv135 (2=0), gen (usual_residents)
gen education_level=mv106
gen education=mv133
recode mv130 (1/2=1)(3/98=0), gen (christian)
recode mv130 (3=1)(1/2=0) (4/98=0), gen (muslim)
gen hhnumber=mv136
gen wealthscore=mv191/100000
gen sstrata=mv022_2
gen dhsclust=mv001
gen dhsnumber=mv002
gen dhsyear=mv007
gen employment=mv732
gen employer=mv719
replace mv717=11 if mv717==96
gen caseid=mcaseid 
gen earn_type=mv741
keep hheadsex hheadage age sex urban always_residents usual_residents education_level education christian muslim hhnumber ///
wealthscore sstrata dhsclust dhsnumber dhsyear caseid employment employer earn_type mv717 smstate_1 mv104

recode education_level (0=1) (1/3=0), gen (no_education)
recode education_level (1=1) (0=0) (2/3=0), gen (primary)
recode education_level (2=1) (0/1=0) (3=0), gen (secondary)
recode education_level (3=1) (0/2=0), gen (higher)
recode mv717 (1/11=1), gen(working)
label var working "Employed"
recode mv717 (1=1)(2/11=0), gen(profess)
label var profess "Professional"
recode mv717 (2=1)(1=0)(3/11=0), gen(clerical)
label var clerical "Clerical"
recode mv717 (3=1)(1/2=0)(4/11=0), gen(sales)
label var sales "Sales"
recode mv717 (4/5=1)(10=1)(1/3=0)(6/9=0)(11=0), gen(agric)
label var agric "Agriculture"
recode mv717 (7=1)(1/6=0)(8/11=0), gen(services)
label var services "Services"
recode mv717 (8=1)(1/7=0)(9/11=0), gen(skilled_manual)
label var skilled_manual "Skilled manual labor"
recode mv717 (9=1)(1/8=0)(10/11=0), gen(unskilled_manual)
label var unskilled_manual "Unskilled manual labor"
recode mv717 (11=1)(1/10=0), gen(other)
label var other "Employed_other labor"
rename (mv717 mv104) (v717 v104)
rename smstate_1 sstate_1
recode employment (1=1) (2/3=0), gen (all_year)
recode employment (1=0) (2/3=1), gen (seasonal_occ)
recode employer (1=1) (2/3=0), gen (family)
recode employer (1=0) (2=1) (3=0), gen (others)
recode employer (1/2=0) (3=1), gen (self)
save "$data\allyrmen-var_int.dta", replace
